package com.shaozj.system.config;

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ComLineRunner {

    @Autowired
    private Environment environment;

    @Value("${spring.data.redis.host:未找到配置}")
    private String redisHost;

    @PostConstruct
    public void checkConfig() {
        log.info("=== @PostConstruct Nacos配置检查 ===");
        log.info("Redis主机: {}", redisHost);
        log.info("数据源URL: {}", environment.getProperty("spring.datasource.url", "未找到"));
        log.info("应用名称: {}", environment.getProperty("spring.application.name", "未找到"));

        // 打印所有相关的配置属性
        String[] keys = {
                "spring.data.redis.host",
                "spring.datasource.url",
                "spring.application.name",
                "spring.cloud.nacos.config.server-addr"
        };

        for (String key : keys) {
            String value = environment.getProperty(key, "未配置");
            log.info("{} = {}", key, value);
        }

        log.info("=== @PostConstruct 配置检查结束 ===");
    }
}
